var _set = require("./../../API/set.js");
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // timetext:'60s后再次发送',
    timetext:"获取验证码",
    disabled: !1,
    active: !1,
    code:'',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var self = this;
    wx.login({
      success (res) {
          console.log(res)
        if (res.code) {
          //发起网络请求
          self.setData({
             code:res.code
         })
        } else {
          // console.log('登录失败！' + res.errMsg)
        }
      }
    })
  },
  phoneChange:function(e){
    this.setData({
      phone:e.detail.value
    })
  },
  captchaChange:function(e){
    this.setData({
      captcha:e.detail.value
    })
  },
  code: function() {
    var i = this;
    return this.data.phone ? /^1[3456789]\d{9}$/.test(i.data.phone) ? void (0, _set.registerVerify)({
      type:'login',
      mobile:this.data.phone
    }).then(function(t) {
        i.setData({
            disabled: !0,
            active: !0
        });
        var a = 60, e = setInterval(function() {
            --a < 0 ? (clearInterval(e), i.setData({
                disabled: !1,
                active: !1,
                timetext: "重新获取"
            })) : i.setData({
                timetext: "剩余 " + a + "s"
            });
        }, 1e3);
        return app.Tips({
            title: "发送成功",
            icon: "success"
        });
    }).catch(function(t) {
        i.setData({
            disabled: !1,
        });
        return app.Tips({
            title: t
        });
    }) : app.Tips({
        title: "请输入正确的手机号码！"
    }) : app.Tips({
        title: "请填写手机号码！"
    });
},
editPwd: function() {
  var a = this;
  return this.data.phone ? /^1[3456789]\d{9}$/.test(this.data.phone) ? this.data.captcha ? 
  void (0, _set.mpLogin)({
      mobile: this.data.phone,
      code: this.data.code,
      verify_code:this.data.captcha,
      login_type:"mobile&code"
  }).then(function(t) {
    wx.setStorage({
      key:"token",
      data:t.data.token
    });
    wx.setStorage({
      key:"userInfo",
      data:t.data.userInfo
    })
    app.globalData.token = t.data.token,app.globalData.userInfo = t.data.userInfo;
    app.globalData.isLog = 1;
    app.globalData.addrInfo ={};
      return app.Tips({
          title: "绑定成功",
          icon: "success"
      }, {
          tab: 6,
          url: "/pages/user/user"
      });
  }).catch(function(t) {
      return app.Tips({
          title: t
      });
  }) : app.Tips({
      title: "请填写验证码"
  }) : app.Tips({
      title: "请输入正确的手机号码！"
  }) : app.Tips({
      title: "请填写手机号码！"
  });
},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})